package com.example.home.adapter.provider

import androidx.databinding.DataBindingUtil
import com.alibaba.android.arouter.launcher.ARouter
import com.chad.library.adapter.base.provider.BaseItemProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.common.RouterPath
import com.example.home.R
import com.example.home.adapter.NominateItemType
import com.example.home.databinding.ItemVideoCardViewBinding
import com.example.entity.BaseEntity
import com.example.home.entity.viewdata.VideoCardViewData
import java.sql.RowId

class VideoCardProvider constructor(private val type : Int,private val layoutResId : Int): BaseItemProvider<BaseEntity>() {
    override val itemViewType: Int = type
    override val layoutId: Int = layoutResId

    override fun onViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        DataBindingUtil.bind<ItemVideoCardViewBinding>(viewHolder.itemView)
    }

    override fun convert(helper: BaseViewHolder, item: BaseEntity) {
        var dataBinding=helper.getBinding<ItemVideoCardViewBinding>()

        if (item!=null && dataBinding!=null){
            var entity = item as VideoCardViewData
            //添加点击事件进入详情
            dataBinding.ivVideoCover.setOnClickListener {
                //点击进入详情页面
                ARouter.getInstance().build(RouterPath.PATH_ACTIVITY_VIDEO)
                    .withString("playerUrl",entity.playerUrl).navigation()
            }

            dataBinding.viewData = entity
            dataBinding.executePendingBindings()
        }
    }
}